#ifndef INCLUDE_STRING_H_
#define INCLUDE_STRING_H_

#include <types.h>
#include <panic.h>

void memcpy(uint8_t *dest, const uint8_t *src, uint32_t len)
{
	assert(dest != NULL && src != NULL);
	for (; len != 0; len--) {
		*dest++ = *src++;
	}
}

void memset(void *dest, uint8_t val, uint32_t len)
{
	assert(dest != NULL);
	uint8_t *dst = (uint8_t *)dest;

	for ( ; len != 0; len--) {
		*dst++ = val;
	}
}

void bzero(void *dest, uint32_t len)
{
	assert(dest != NULL);
	memset(dest, 0, len);
}

int strcmp(const char *str1, const char *str2)
{
	assert(str1 != NULL && str2 != NULL);
    while (*str1 && *str2 && *str1 == *str2) {
        str1++;
        str2++;
    }

    return *str1 - *str2;
}

char *strcpy(char *dest, const char *src)
{
	char *tmp = dest;

	while (*src) {
	      *dest++ = *src++;
	}

	*dest = '\0';

	return tmp;
}

char *strcat(char *dest, const char *src)
{
	char *cp = dest;

	while (*cp) {
	      cp++;
	}

	while ((*cp++ = *src++))
	      ;

	return dest;
}

int strlen(const char *src)
{
	const char *eos = src;

        while (*eos++)
	      ;

	return (eos - src - 1);
}

#endif 	// INCLUDE_STRING_H_

